import pymysql
# 封装数据库工具类
class DBUtil(object):
    conn = None

    @classmethod
    def __get_conn(cls):
        if cls.conn is None:
            cls.conn = pymysql.connect(host="localhost",
                                       port=3306,
                                       user="root",
                                       password="123456",
                                       database="test_db",
                                       charset="utf8")
        return cls.conn

    @classmethod
    def __close_conn(cls):
        if cls.conn is not None:
            cls.conn.close()
            cls.conn = None
